package com.zb.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>添加描述信息</p>
 *
 * @author 李柯
 * @since 2022年11月15日 10:46
 */
@Configuration
public class MQConfig {

    public static final String PAY_EXCHANGE = "pay_exchange";
    public static final String PAY_QUEUE = "pay_queue";
    public static final String PAY_ROUTING = "pay_routing";

    @Bean(PAY_EXCHANGE)
    public Exchange createPayExchange() {
        return ExchangeBuilder.topicExchange(PAY_EXCHANGE).durable(true).build();
    }

    @Bean(PAY_QUEUE)
    public Queue createPayQueue() {
        return new Queue(PAY_QUEUE, true, false, false, null);
    }

    @Bean
    public Binding bindingPayExchangeAndQueue(@Qualifier(PAY_EXCHANGE) Exchange exchange, @Qualifier(PAY_QUEUE) Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(PAY_ROUTING).noargs();
    }


    public static final String SECKILL_EXCHANGE = "seckill_exchange";
    public static final String SECKILL_QUEUE = "seckill_queue";
    public static final String SECKILL_ROUTING = "seckill_routing";

    @Bean(SECKILL_EXCHANGE)
    public Exchange createSeckillExchange() {
        return ExchangeBuilder.topicExchange(SECKILL_EXCHANGE).durable(true).build();
    }

    @Bean(SECKILL_QUEUE)
    public Queue createSeckillQueue() {
        return new Queue(SECKILL_QUEUE, true, false, false, null);
    }

    @Bean
    public Binding bindingSeckillExchangeAndQueue(@Qualifier(SECKILL_EXCHANGE) Exchange exchange, @Qualifier(SECKILL_QUEUE) Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(SECKILL_ROUTING).noargs();
    }

}
